<?php

// +----------------------------------------------------------------------
// | liangjian.ltd
//版权所有：新动力线上书店
//开发者：Toren工作室
//开发时间：2022-09-01
// +----------------------------------------------------------------------

namespace app\index\controller;

use app\api\model\ShopGoods;
use think\admin\Controller;

/**
 * Class Index
 * @package app\index\controller
 */
class Index extends Controller
{
    public function index()
    {
        $this->redirect(sysuri('admin/login/index'));
    }
    public function CreateGoodsQrcode()
    {
        $goods = ShopGoods::where(array(['id','>',24]))->order(array('id'=>'asc'))->select()->toArray();
        foreach($goods as &$gv) {
            $data['qrcode_path'] = \Common::createQrcode(array(
                'goods_id'  =>$gv['id']
            ), 0, $gv['name']);
        }
        return true;
    }

    public function CreateGoodsQrcodeByCode()
    {
        $code = input('code','');
        if (empty($code))return "商品编码必传";
        $goods = ShopGoods::where(array(['code','=',$code]))->order(array('id'=>'asc'))->select()->toArray();
        foreach($goods as &$gv) {
            $data['qrcode_path'] = \Common::createQrcode(array(
                'goods_id'  =>$gv['id']
            ), 0, $gv['name']);
            return $data['qrcode_path'];
        }
        return "数据获取失败";
    }
    public function preview(){
        if($this->request->isPost()){
            sysconf('data_preview',input('content'));
            $url = \Tools::qrcode($this->request->domain().'/index/index/preview');
            return \Tools::returnMsg(true,$url,'json');
        }
        $data = sysconf('data_preview');
        $this->content =htmlspecialchars_decode($data);
        $this->fetch();
    }
}
